package com.zoran.study.spring.configuration;

import com.zoran.study.spring.common.advice.FrameworkExceptionAdvice;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;

@Configuration
public class ExceptionAdviceConfigurer {

    @Bean("errorMessageSource")
    public MessageSource errorMessageSource() {
        ReloadableResourceBundleMessageSource ms = new ReloadableResourceBundleMessageSource();
        ms.setDefaultEncoding("UTF-8");
        ms.setBasenames("classpath:error-message");
        return ms;
    }

    @Bean
    public FrameworkExceptionAdvice frameworkExceptionAdvice() {
        return new FrameworkExceptionAdvice();
    }

}
